package ess

import (
	"context"
	"encoding/json"
	"es/mysql"
	"github.com/elastic/go-elasticsearch/esapi"
	"log"
	"strconv"
	"strings"
)

func SyncGoods(goods *mysql.Goods) {
	str, _ := json.Marshal(goods)

	req := esapi.IndexRequest{
		Index:      "goods",
		DocumentID: strconv.Itoa(int(goods.ID)),
		Body:       strings.NewReader(string(str)),
		Refresh:    "true",
	}

	// Perform the request with the client.
	res, err := req.Do(context.Background(), es)
	if err != nil {
		log.Fatalf("Error getting response: %s", err)
	}
	defer res.Body.Close()
}
